package com.example.module_enterprise.view


import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_enterprise.adapter.EnterpriseAdapter
import com.example.module_enterprise.databinding.ActivityEnterpriseBinding
import com.example.module_enterprise.vm.EnterpriseViewModel
import com.yuwei.base.BaseActivity
import com.yuwei.common.path.RouterPath
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.ENTERPRISE)
class EnterpriseActivity : BaseActivity<ActivityEnterpriseBinding,EnterpriseViewModel>() {
    val enterpriseAdapter = EnterpriseAdapter()
    override fun initView() {
        binding.enterpriseRv.adapter = enterpriseAdapter
        binding.enterpriseRv.layoutManager = LinearLayoutManager(this)
        vm.getEnterpriseList()
        binding.enterBack.setOnClickListener {
            finish()
        }
        enterpriseAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build(RouterPath.DETAIL_ENTERPRISE)
                .withSerializable("enter",enterpriseAdapter.data[position]).navigation()
        }
    }

    override fun initData() {
        vm.getEnterpriseSuccess.observe(this){
            enterpriseAdapter.data.addAll(it)
            enterpriseAdapter.notifyDataSetChanged()
        }

    }

}